package cn.shentianlan.controller;

import cn.shentianlan.service.DeviceDataService;
import cn.shentianlan.utils.JsonUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
public class DeviceDataController {
    @Resource
    private DeviceDataService deviceDataService;

    @RequestMapping(value = "/showDeviceData.do",method = RequestMethod.POST)
    public void getDeviceData(@RequestParam("gd_dev_id") String id, @RequestParam("date") String date, HttpServletResponse response) throws IOException {
        String deviceDate =  deviceDataService.getDeviceData(id,date);
        response.getWriter().write(deviceDate);
    }

    @RequestMapping(value = "getDeviceDate.do")
    public void getDeviceDate(@RequestParam("gd_dev_id") String id,HttpServletResponse response) throws IOException {
        List<String> deviceDateList = deviceDataService.getDeviceDate(id);
        ObjectMapper mapper = new ObjectMapper();
        String deviceDate = JsonUtils.ObjectToString(deviceDateList);
        response.getWriter().write(deviceDate);
    }

}
